<template>
	<view class="bruce" id="conent">
		<ul class="bubble-bgwall">
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
			<li class="bubble">Vue</li>
		</ul>
		<view class="toptitle" @click="home">
			智能农业监控系统
		</view>
		<view class="showcontent">
			<view class="introduction">
				<scroll-view id="scrollview" scroll-y>
					<view class="content" v-if="contentlist.length==0">
						<view>
							该站站长很懒，什么也没有
						</view>
					</view>
					<view class="content" v-if="contentlist.length>0">
						<view v-for="item in contentlist" :key="item.id">
							<span class="Avatar">
							</span>
							<span class="userid">
								{{item.username}}
							</span>
							<view class="userinfo">
								<span class="usercreatetime">
									{{item.createtime}}
								</span>
								<span class="usercontent">
									<span>{{item.userspeak}}</span>
								</span>
							</view>

						</view>
					</view>
				</scroll-view>
				<form class="formcontent" @submit="submitcontent">
					<input type="text" placeholder-style="color: #1f1f1f;" v-model="message" name="userspeak" />
					<button class="submit" size="mini" form-type="submit">发送</button>
				</form>
			</view>
		</view>
		<view class="righttop">
			<span @click="mypage">欢迎：{{userid}}</span>
		</view>
		<view class="winfroted-glass">
			<ul class="nav1">
				<li class="title1" @click="home">系统简介</li>
				<li class="title1" @click="LoginRegister">进入系统</li>
				<li class="title1" @click="relatedTechnologies">相关技术</li>
				<li class="title1" @click="InsiteCommunity">进入社区</li>
				<li class="title1" @click="teamSpirit">团队风采</li>
				<li class="title1" @click="aboutUs">关于我们</li>
			</ul>
		</view>
		<view class="andshowcontent">
			<view class="andintroduction">
				<view class="Refresh" @click="Refreshs">
					<image class="topRefresh" src="../../static/Refresh.png"></image>
				</view>
				<scroll-view id="andscrollview" scroll-y>
					<view class="content" v-if="contentlist.length==0">
						<view>
							该站很冷清，什么也没有
						</view>
					</view>
					<view class="content" v-if="contentlist.length>0">
						<view v-for="item in contentlist" :key="item.id">
							<span class="Avatar">
							</span>
							<span class="userid">
								{{item.username}}
							</span>
							<span class="usercontent">
								{{item.userspeak}}
							</span>
						</view>
					</view>
				</scroll-view>
				<view class="top" @click="navigateBack">
					<image class="pic" src="../../static/left.png"></image>
				</view>
				<form class="andformcontent" @submit="submitcontent">
					<input type="text" placeholder-style="color: #1f1f1f;" v-model="message" name="userspeak" />
					<button class="submit" size="mini" form-type="submit">发送</button>
				</form>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		VUE_APP_BASE_URL
	} from 'utils/request.js';
	import {
		myrequest
	} from '../../utils/request';
	import {
		formatDate
	} from "../../utils/time.js";
	export default {
		data() {
			return {
				cssid: '',
				userid: 'itheima0001',
				contentlist: [],
				message: '我也来两句'
			}
		},
		onLoad(e) {
			this.cssid = e.cssid;
		},
		mounted() {
			this.draw();
			this.getcontentlist();
		},
		methods: {
			Refreshs(e) {
				this.getcontentlist()
			},
			submitcontent(e) {
				if (e.detail.value.userspeak != ' ' && e.detail.value.userspeak != '') {
					let userid = uni.getStorageSync('userid')
					uni.request({
						url: VUE_APP_BASE_URL + '/speak/addUserinfo',
						data: {
							userid: userid,
							userspeak: e.detail.value.userspeak
						},
						header: {
							"Content-Type": "application/x-www-form-urlencoded"
						},
						method: "POST",
						success: (res) => {
							if (res.data.code == 200) {
								// console.log(res);
								/*如果验证服务器成功则执行成功提示*/
								uni.showToast({
									title: "发布成功",
									icon: 'success',
									duration: 1000
								});
								// console.log(res.data.data.userid);
								setTimeout(() => {
									this.message = ''
									this.getcontentlist();
								}, 500);
							} else {
								uni.showToast({
									title: "请先登录",
									icon: 'error',
									duration: 2000
								});
							}
						}
					})
				} else {
					uni.showToast({
						title: '请输入内容',
						icon: 'error',
						duration: 1000
					})
				}
			},
			async getcontentlist(e) {
				let username = uni.getStorageSync('username');
				// console.log(userid);
				let res = await myrequest({
					//await的作用为需要等待$myhttp请求成功后下执行下面的进程
					url: '/speak/speakList',

					data: {
						pageNum: 1,
						pageSize: 100
					},
					method: "POST",
				}).then(res => {
					if (Array.isArray(res.data.data)) {
						this.contentlist = res.data.data.map(item => {
							// 格式化时间戳
							item.createtime = formatDate(item.createtime * 1000);
							return item;
						});
					}
					this.contentlist = res.data.data.slice().reverse()
					console.log(res);
				});
			},
			navigateBack(){
				uni.navigateBack({
					delta:1
				})
			},
			mypage() {
				uni.navigateTo({
					url: '/pages/mypage/mypage?cssid=' + this.cssid,
					animationType: 'fade-in', // 指定动画类型
					animationDuration: 300 // 动画时长
				})
			},
			teamSpirit() {
				uni.navigateTo({
					url: '/pages/teamSpirit/teamSpirit?cssid=' + this.cssid,
					animationType: 'fade-in', // 指定动画类型
					animationDuration: 300 // 动画时长
				})
			},
			InsiteCommunity() {
				uni.navigateTo({
					url: '/pages/InsiteCommunity/InsiteCommunity?cssid=' + this.cssid,
					animationType: 'fade-in', // 指定动画类型
					animationDuration: 300 // 动画时长
				})
			},
			relatedTechnologies() {
				uni.navigateTo({
					url: '/pages/relatedTechnologies/relatedTechnologies?cssid=' + this.cssid,
					animationType: 'fade-in', // 指定动画类型
					animationDuration: 300 // 动画时长
				})
			},

			aboutUs() {
				uni.navigateTo({
					url: '/pages/aboutUs/aboutUs?cssid=' + this.cssid,
					animationType: 'fade-in', // 指定动画类型
					animationDuration: 300 // 动画时长
				})
			},
			LoginRegister(e) {
				let userid = uni.getStorageSync('userid')
				if (userid !== '') {
					uni.navigateTo({
						url: '/pages/Deviceinformation/Deviceinformation?cssid=' + this.cssid,
						animationType: 'fade-in', // 指定动画类型
						animationDuration: 300 // 动画时长
					})
				} else {
					uni.navigateTo({
						url: '/pages/LoginRegister/LoginRegister?cssid=' + this.cssid,
						animationType: 'fade-in', // 指定动画类型
						animationDuration: 300 // 动画时长
					})
				}
			},
			home() {
				uni.navigateTo({
					url: '/pages/home/home',
					animationType: 'zoom-fade-out', // 指定动画类型
					animationDuration: 100 // 动画时长
				})
			},
			draw(e) {
				let themes = document.querySelector('.bruce');
				let color = document.querySelectorAll(".bubble")
				let userid = uni.getStorageSync('userid')
				let username = uni.getStorageSync('username');
				this.userid = username
				if (this.cssid == 1) {
					this.button = false;
					this.title = "白天模式"
					this.cssid = 1
					themes.style.background = 'linear-gradient(270deg, #0a0b35, #120144)'
					color.forEach(function(element) {
						element.style.color = '#83c0f7'
					});

				} else {
					this.title = "夜间模式"
					this.button = true;
					this.cssid = 0
					themes.style.background = 'linear-gradient(270deg, #819cad, #81a5bd)'
					color.forEach(function(element) {
						element.style.color = '#6661e6'
					});

				}
			}

		}
	}
</script>
<style lang="scss">
	@media screen and (min-width: 640px) {
		#conent {
			background: #030812 !important;

			.toptitle {
				position: fixed;
				margin-left: 5px;
				width: 100%;
				padding: 20px;
				z-index: 12;
				font-size: 24px;
				font-family: "楷体", sans-serif;
				top: 0px;
				font-weight: bold;
				color: #d8d8d8;
				left: 0;
				display: block;
				background: #393d49;
				background-image: url('https://gd-hbimg.huaban.com/23c7d4ff432744f58bbd2087eb6745a4f66d95c757996-Z6BbHB_fw1200');
				background-repeat: no-repeat;
				background-size: 100vw;
			}

			.righttop {
				position: fixed;
				margin-left: 5px;
				width: 50%;
				padding: 20px 40px 20px 0;
				z-index: 12;
				font-size: 24px;
				font-family: "楷体", sans-serif;
				top: 0;
				font-weight: bold;
				color: #d8d8d8;
				right: 0;
				display: block;
				text-align: right;
				background: transparent;

				span {
					&:hover {
						color: #009688;
					}
				}
			}

			.showcontent {
				background: rgba(255, 255, 255, 0.5);
				z-index: 10;
				display: block;
				justify-content: center;
				position: fixed;
				left: 0;
				margin: 0 50px 0 50px;
				width: 100%;
				height: 100%;
				backdrop-filter: blur(3px);

				.introduction {
					background-color: rgba(0, 0, 0, 0.126);
					display: block;
					overflow: hidden;
					box-sizing: border-box;
					position: relative;
					margin-top: 120px;
					margin-left: 120px;
					margin-right: 100px;
					padding: 20px;
					border-radius: 5px;

					#scrollview {
						width: 100%;
						height: 80vh;
						background-color: transparent;

						h2,
						h3 {
							color: #111111;
							padding: 5px;
						}

						p {
							color: #eee;
							line-height: 35px;
							text-indent: 2em;
							font-size: 18px;

							span {
								padding: 5px;
								background-image: linear-gradient(to right, #171f1f, #002622);
								background-repeat: no-repeat;
								background-size: 0% 2px;
								background-position: left bottom;
								transition: background-size 1s;

								a {
									color: #eee;
									text-decoration: none;
								}

								&:hover {
									background-size: 100% 2px;
								}
							}

						}

						.content {
							padding: 30px 0 0 0;

							.Avatar {
								display: block;
								width: 50px;
								height: 50px;
								border-radius: 5px;
								background-image: url('../../static/logo.png');
								background-color: #fff;
								background-position: center center;
								background-size: cover;
							}

							.userid {
								background-color: transparent;
								position: relative;
								left: 0px;
								top: -70px;
								font-size: 12px;
								width: 50px;
								white-space: nowrap;
								/* 防止文字换行 */
								overflow: hidden;
								/* 隐藏溢出容器的内容 */
								text-overflow: ellipsis;
								height: 12px;
								display: block;
								padding: 2px;
								line-height: 12px;
							}

							.userinfo {
								background-color: transparent;
								position: relative;
								display: inline-block;
								left: 60px;
								top: -90px;
								display: flex;
								flex-direction: column;

								.usercontent {
									background-color: transparent;

									span {
										background-color: #819cad;
										position: relative;
										display: inline-block;
										white-space: pre-wrap;
										/* 保留换行符，并在需要时自动换行 */
										word-wrap: break-word;
										/* 防止长单词或URL溢出容器 */
										max-width: 70vw;
										font-size: 18px;
										text-align: left;
										border-radius: 5px;
										padding: 10px;
									}
								}

								.usercreatetime {
									background-color: transparent;
									width: 160px;
									position: relative;
									padding-bottom: 10px;
									color: #ffffff;
									// left: 60px;
									// top: -100px;
									display: inline-block;
								}
							}


						}


					}

					.formcontent {
						padding: 10px;
						display: inline-flex;
						line-height: 20px;
						top: -20px;
						width: 95%;
						overflow: hidden;
						margin: -20px auto;
						position: relative;
						background-color: transparent;
						border-radius: 5px;

						input {
							background-color: #ffffff;
							padding: 5px;
							display: inline-flex;
							flex: 4;
							color: #000;
							width: 60vw;
							margin-right: 15px;
							border-radius: 5px;
						}

						.submit {
							background-color: #009688;
							display: inline-flex;
							left: 0;
							flex: 1;
						}
					}

				}

			}


			.winfroted-glass {
				background-color: transparent;
				z-index: 10;
				width: 140px;
				display: flex;
				position: fixed;
				left: 0px;
				top: 10px;

				.nav1 {
					margin-top: 30px;
					width: 120px;
					height: 100vh;
					background-color: #393d49;
					position: relative;
					display: block;
					margin-left: 5px;
					box-sizing: border-box;
					padding: 50px 0 0 0;
					border-left: 5px solid #222e6f;
					justify-content: center;
					text-align: center;

					.title1 {
						width: 100%;
						margin: 10px auto;
						padding: 10px 0;
						list-style: none;
						text-align: center;
						color: #d8d8d8;
						transition: background-color 0.3s ease;

						&:hover {
							background: #009688;
							border-right: #ffffff 2px solid;
							cursor: pointer;
						}
					}
				}
			}

			.andshowcontent {
				display: none;
			}
		}
	}

	.bruce {
		background-image: linear-gradient(270deg, #819cad, #81a5bd);
		height: 100vh;
		display: flex;
		justify-content: center;
		align-items: center;
		overflow: hidden;

		.winfroted-glass {
			display: none;
		}

		.showcontent {
			display: none;
		}

		.toptitle {
			display: none;
		}

		.righttop {
			display: none;
		}

		.frosted-glass {
			box-sizing: border-box;
			overflow: hidden;
			position: fixed;
			display: flex;
			top: 20vh;
			align-items: center;
			width: 72vw;
			height: 60vh;
			border-radius: 1%;
			box-shadow: 0 0.3px 0.7px rgba(0, 0, 0, 0.126), 0 0.9px 1.7px rgba(0, 0, 0, 0.179), 0 1.8px 3.5px rgba(0, 0, 0, 0.224), 0 3.7px 7.3px rgba(0, 0, 0, 0.277), 0 10px 20px rgba(0, 0, 0, 0.4);
			backdrop-filter: blur(10px);
			transition: 0.5s ease;
			animation: code 2s;

		}

		@media (max-width: 640px) {
			.frosted-glass .title {
				font-size: 2em;
			}
		}
	}

	.bubble-bgwall {
		position: relative;
		width: 100%;
		height: 100%;
		list-style: none;
		padding: 0;
		margin: 0;
		display: flex;
		flex-direction: column;
		align-items: flex-end;
	}

	.andshowcontent {
		z-index: 10;
		display: block;
		justify-content: center;
		position: fixed;
		margin: 0 50px 0 50px;
		width: 100%;
		height: 100%;

		.andintroduction {
			background-color: rgba(0, 0, 0, 0.626);
			display: block;
			overflow: hidden;
			box-sizing: border-box;
			position: relative;
			margin-top: 30px;
			margin-left: 10px;
			margin-right: 10px;
			padding: 10px;
			border-radius: 5px;

			.Refresh {
				display: block;
				position: relative;
				padding: 10px;
				top: 30px;
				width: 50px;
				height: 50px;
				z-index: 10;
				right: 10px;
				float: right;
				background-color: rgba(67, 230, 244, 0.2);
				overflow: hidden;
				border-radius: 50%;
				box-sizing: border-box;
				filter: drop-shadow(1px 1px 20px #60fff5);

				.topRefresh {
					width: 100%;
					height: 100%;
				}

			}

			#andscrollview {
				width: 100%;
				height: 90vh;
				color: #eaeaea;
				font-size: 18px;
				background-color: transparent;

				h2,
				h3 {
					color: #eaeaea;
					padding: 5px;
				}

				p {
					color: #dfdfdf;
					line-height: 35px;
					text-indent: 2em;
					font-size: 16px;

					a {
						color: #eee;
						text-decoration: none;
					}

					span {
						padding: 5px;
						background-image: linear-gradient(to right, #171f1f, #002622);
						background-repeat: no-repeat;
						background-size: 0% 2px;
						background-position: left bottom;
						transition: background-size 1s;

						&:hover {
							background-size: 100% 2px;
						}
					}

				}

				.content {
					padding: 5px;

					.Avatar {
						display: block;
						width: 50px;
						height: 50px;
						border-radius: 5px;
						background-image: url('../../static/logo.png');
						background-color: #fff;
						background-position: center center;
						background-size: cover;
					}

					.userid {
						background-color: transparent;
						position: relative;
						left: 60px;
						top: -52px;
						font-size: 12px;
						width: 100px;
						height: 12px;
						display: block;
						padding: 2px;
						line-height: 12px;
					}

					.usercontent {
						background-color: #819cad;
						position: relative;
						left: 60px;
						top: -45px;
						display: inline-block;
						white-space: pre-wrap;
						/* 保留换行符，并在需要时自动换行 */
						word-wrap: break-word;
						/* 防止长单词或URL溢出容器 */
						max-width: 62vw;
						font-size: 18px;
						text-align: left;
						border-radius: 5px;
						padding: 10px;
					}
				}

			}

			.andformcontent {
				padding: 10px;
				display: inline-flex;
				line-height: 20px;
				top: -80px;
				width: 95%;
				overflow: hidden;
				margin: -20px auto;
				position: relative;
				background-color: transparent;
				border-radius: 5px;

				input {
					background-color: #ffffff;
					padding: 5px;
					display: inline-flex;
					flex: 4;
					color: #000;
					width: 55vw;
					margin-right: 15px;
					border-radius: 5px;
				}

				.submit {
					background-color: #009688;
					display: inline-flex;
					left: 0;
					flex: 1;
				}
			}

		}

		.top {
			display: block;
			position: relative;
			padding: 10px;
			bottom: 150px;
			width: 50px;
			height: 50px;
			right: 0;
			float: right;
			background-color: #009688;
			overflow: hidden;
			border-radius: 50%;
			box-sizing: border-box;

			.pic {
				width: 100%;
				height: 100%;
			}
		}
	}

	.bubble {
		display: flex;
		position: absolute;
		bottom: -200px;
		justify-content: center;
		align-items: center;
		border-radius: 10px;
		width: 50px;
		height: 50px;
		background-color: rgba(255, 255, 255, 0.15);
		color: #44397a;
		animation: bubble 15s infinite;
	}

	.bubble:nth-child(1) {
		left: 10%;
	}

	.bubble:nth-child(2) {
		left: 20%;
		width: 90px;
		height: 90px;
		animation-duration: 7s;
		animation-delay: 2s;
	}

	.bubble:nth-child(3) {
		left: 25%;
		animation-delay: 4s;
	}

	.bubble:nth-child(4) {
		left: 40%;
		width: 60px;
		height: 60px;
		background-color: rgba(255, 255, 255, 0.3);
		animation-duration: 8s;
	}

	.bubble:nth-child(5) {
		left: 70%;
	}

	.bubble:nth-child(6) {
		left: 80%;
		width: 120px;
		height: 120px;
		background-color: rgba(255, 255, 255, 0.2);
		animation-delay: 3s;
	}

	.bubble:nth-child(7) {
		left: 32%;
		width: 160px;
		height: 160px;
		animation-delay: 2s;
	}

	.bubble:nth-child(8) {
		left: 55%;
		width: 40px;
		height: 40px;
		font-size: 12px;
		animation-duration: 15s;
		animation-delay: 4s;
	}

	.bubble:nth-child(9) {
		left: 25%;
		width: 40px;
		height: 40px;
		background-color: rgba(255, 255, 255, 0.3);
		font-size: 12px;
		animation-duration: 12s;
		animation-delay: 2s;
	}

	.bubble:nth-child(10) {
		left: 85%;
		width: 160px;
		height: 160px;
		animation-delay: 5s;
	}

	@keyframes bubble {
		0% {
			opacity: 0.5;
			transform: translateY(0) rotate(45deg);
		}

		25% {
			opacity: 0.75;
			transform: translateY(-400px) rotate(90deg);
		}

		50% {
			opacity: 1;
			transform: translateY(-600px) rotate(135deg);
		}

		100% {
			opacity: 0;
			transform: translateY(-1000px) rotate(180deg);
		}
	}

	@keyframes code {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}
</style>